const CompressionPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css']
const webpack = require('webpack');
module.exports = {
    devServer: {
        disableHostCheck: true,
        proxy: {
            '/freight': {
                // target: 'http://113.133.177.216:8089',
                 target: 'http://localhost:8089',
                //     target: 'http://192.168.0.103:8089',
                ws: true,
                changeOrigin: true
            },
            '/foo': {
                target: '<other_url>'
            }
        }
    },
    // 打包时不生成.map文件 避免看到源码
    productionSourceMap: false,
    // 部署优化
    configureWebpack: {
        // 使用CDN
        externals: {
            vue: 'Vue',
            'vue-i18n': 'VueI18n',
            VueI18n: 'vue-i18n',
            axios: 'axios',
            'vue-router': 'VueRouter',
            // VueRouter:'vue-router',
            vuex: 'Vuex',
            'view-design': 'iview',
            // iview:'view-design',
            echarts: 'echarts',
            apexcharts: 'ApexCharts',
            // 'vue-apexcharts': 'VueApexCharts',
            VueApexCharts: 'vue-apexcharts',
            xlsx: 'XLSX',
            dplayer: 'DPlayer',
            'print-js': 'printJS',
            printJS: 'print-js',
            html2canvas: 'html2canvas',
            // 'vue-json-pretty': 'VueJsonPretty',
            VueJsonPretty: 'vue-json-pretty',
            // 'vue-lazyload': 'VueLazyload',
            VueLazyload: "vue-lazyload",
            gitalk: 'Gitalk',
            // Cookies: 'js-cookie',
            wangEditor: 'wangEditor',
            quill: 'Quill',
            stompjs: 'Stomp',
            // 'sockjs-client': 'SockJS',
            SockJS: 'sockjs-client',
            vuedraggable: 'vuedraggable',
            viewerjs: 'Viewer'
        },
        // GZIP压缩
        plugins: [
            new CompressionPlugin({
                test: /\.js$|\.html$|\.css/, // 匹配文件
                threshold: 10240, // 对超过10k文件压缩
                minRatio: 0.8
            }),
            new webpack.optimize.LimitChunkCountPlugin({
                maxChunks: 5,
                minChunkSize: 100
            })
        ]
    }
}
